/**
  ******************************************************************************
  * @file           : state_machine_drv.cpp
  * @author         : Tessia
  * @brief          : None
  * @attention      : None
  * @date           : 2024/3/14
  ******************************************************************************
  */



#include "state_machine_drv.h"


sentry_state_machine::sentry_state_machine(state_transform (*state_transform_table_)[EVENT_NUM], osSemaphoreId_t *binary_sem_)
                    :state(standby), last_event(none), state_last(standby),state_transform_table(state_transform_table_),
                    binary_sem(binary_sem_){
    osSemaphoreAcquire(*binary_sem, 0);
}

void sentry_state_machine::event_happen(sentry_event event) {
    state_last = state == state_transform_table[state][event].next_state ? state_last : state;
    state = state_transform_table[state][event].next_state;
    if(state != state_last){
        osSemaphoreRelease(*binary_sem);
    }
    last_event = event;
}

sentry_state sentry_state_machine::get_current_state(){
    return(state);
}

void sentry_state_machine::go_to_specified_state(sentry_state specified_state){
    state_last = state;
    state = specified_state;
    last_event = logic_operate;
}


/**
 * 调试状态转移表格
 */
state_transform debug_state_table[STATE_NUM][EVENT_NUM]={
        /*******************              standby            *****************/
        {{standby, none, standby},
                {standby, match_begin, patrol},
                {standby, turn_off_auto, standby},
                {standby, turn_on_auto, mid_priority_pathfinding},
                {standby, target_detected, standby},
                {standby, target_disappear, standby},
                {standby, being_hit, standby},
                {standby, ammunition_capacity_reached_limit, standby},
                {standby, HP_low, standby},
                {standby, logic_operate, standby},
                {standby, HP_regeneration, standby},
                {standby, outpost_HP_low, standby},
                {standby, revive, standby},
                {standby, outpost_destroyed, standby}},


        /*******************              attack            *****************/
        {{attack, none, attack},
                {attack, match_begin, attack},
                {attack, turn_off_auto, standby},
                {attack, turn_on_auto, error},
                {attack, target_detected, attack},
                {attack, target_disappear, low_priority_pathfinding},
                {attack, being_hit, attack},
                {attack, ammunition_capacity_reached_limit, logic},
                {attack, HP_low, logic},
                {attack, logic_operate, logic},
                {attack, HP_regeneration, attack},
                {attack, outpost_HP_low, attack},
                {attack, revive, attack},
                {attack, outpost_destroyed, attack}},

        /*******************              high_priority_pathfinding            *****************/
        {{high_priority_pathfinding, none, high_priority_pathfinding},
                {high_priority_pathfinding, match_begin, error},
                {high_priority_pathfinding, turn_off_auto, standby},
                {high_priority_pathfinding, turn_on_auto, error},
                {high_priority_pathfinding, target_detected, high_priority_pathfinding},
                {high_priority_pathfinding, target_disappear, high_priority_pathfinding},
                {high_priority_pathfinding, being_hit, high_priority_pathfinding},
                {high_priority_pathfinding, ammunition_capacity_reached_limit, high_priority_pathfinding},
                {high_priority_pathfinding, HP_low, high_priority_pathfinding},
                {high_priority_pathfinding, logic_operate, high_priority_pathfinding},
                {high_priority_pathfinding, HP_regeneration, patrol},
                {high_priority_pathfinding, outpost_HP_low, high_priority_pathfinding},
                {high_priority_pathfinding, revive, high_priority_pathfinding},
                {high_priority_pathfinding, outpost_destroyed, high_priority_pathfinding}},

        /*******************              mid_priority_pathfinding            *****************/
        {{mid_priority_pathfinding, none, mid_priority_pathfinding},
                {mid_priority_pathfinding, match_begin, error},
                {mid_priority_pathfinding, turn_off_auto, standby},
                {mid_priority_pathfinding, turn_on_auto, error},
                {mid_priority_pathfinding, target_detected, mid_priority_pathfinding},
                {mid_priority_pathfinding, target_disappear, mid_priority_pathfinding},
                {mid_priority_pathfinding, being_hit, mid_priority_pathfinding},
                {mid_priority_pathfinding, ammunition_capacity_reached_limit, logic},
                {mid_priority_pathfinding, HP_low, logic},
                {mid_priority_pathfinding, logic_operate, mid_priority_pathfinding},
                {mid_priority_pathfinding, HP_regeneration, patrol},
                {mid_priority_pathfinding, outpost_HP_low, mid_priority_pathfinding},
                {mid_priority_pathfinding, revive, mid_priority_pathfinding},
                {mid_priority_pathfinding, outpost_destroyed, mid_priority_pathfinding}},

        /*******************              low_priority_pathfinding            *****************/
        {{low_priority_pathfinding, none, low_priority_pathfinding},
                {low_priority_pathfinding, match_begin, error},
                {low_priority_pathfinding, turn_off_auto, standby},
                {low_priority_pathfinding, turn_on_auto, error},
                {low_priority_pathfinding, target_detected, attack},
                {low_priority_pathfinding, target_disappear, error},
                {low_priority_pathfinding, being_hit, low_priority_pathfinding},
                {low_priority_pathfinding, ammunition_capacity_reached_limit, logic},
                {low_priority_pathfinding, HP_low, logic},
                {low_priority_pathfinding, logic_operate, logic},
                {low_priority_pathfinding, HP_regeneration, low_priority_pathfinding},
                {low_priority_pathfinding, outpost_HP_low, low_priority_pathfinding},
                {low_priority_pathfinding, revive, low_priority_pathfinding},
                {low_priority_pathfinding, outpost_destroyed, low_priority_pathfinding}},

        /*******************              patrol            *****************/
        {{patrol, none, patrol},
                {patrol, match_begin, error},
                {patrol, turn_off_auto, standby},
                {patrol, turn_on_auto, error},
                {patrol, target_detected, attack},
                {patrol, target_disappear, patrol},
                {patrol, being_hit, patrol},
                {patrol, ammunition_capacity_reached_limit, logic},
                {patrol, HP_low, logic},
                {patrol, logic_operate, logic},
                {patrol, HP_regeneration, patrol},
                {patrol, outpost_HP_low, patrol},
                {patrol, revive, patrol},
                {patrol, outpost_destroyed, patrol}},

        /*******************              stationary_defense            *****************/
        {{stationary_defense, none, stationary_defense},
                {stationary_defense, match_begin, error},
                {stationary_defense, turn_off_auto, standby},
                {stationary_defense, turn_on_auto, error},
                {stationary_defense, target_detected, stationary_defense},
                {stationary_defense, target_disappear, stationary_defense},
                {stationary_defense, being_hit, stationary_defense},  ///这里先测试，后面改为short_range_mobile_defense
                {stationary_defense, ammunition_capacity_reached_limit, constrained_defense},
                {stationary_defense, HP_low, constrained_defense},
                {stationary_defense, logic_operate, constrained_defense},
                {stationary_defense, HP_regeneration, patrol},
                {stationary_defense, outpost_HP_low, stationary_defense},
                {stationary_defense, revive, stationary_defense},
                {stationary_defense, outpost_destroyed, stationary_defense}},


        /*******************              constrained_defense            *****************/
        {{constrained_defense, none, constrained_defense},
                {constrained_defense, match_begin, error},
                {constrained_defense, turn_off_auto, standby},
                {constrained_defense, turn_on_auto, error},
                {constrained_defense, target_detected, attack},
                {constrained_defense, target_disappear, patrol},
                {constrained_defense, being_hit, patrol},
                {constrained_defense, ammunition_capacity_reached_limit, constrained_defense},
                {constrained_defense, HP_low, constrained_defense},
                {constrained_defense, logic_operate, constrained_defense},
                {constrained_defense, HP_regeneration, patrol},
                {constrained_defense, outpost_HP_low, constrained_defense},
                {constrained_defense, revive, constrained_defense},
                {constrained_defense, outpost_destroyed, constrained_defense}},


        /*******************              error            *****************/
        {{error, none, error},
                {error, match_begin, error},
                {error, turn_off_auto, standby},
                {error, turn_on_auto, error},
                {error, target_detected, error},
                {error, target_disappear, error},
                {error, being_hit, error},
                {error, ammunition_capacity_reached_limit, error},
                {error, HP_low, error},
                {error, logic_operate, error},
                {error, HP_regeneration, error},
                {error, outpost_HP_low, error},
                {error, revive, error},
                {error, outpost_destroyed, error}},


        /*******************              logic            *****************/
        {{logic, none, logic},
                {logic, match_begin, logic},
                {logic, turn_off_auto, standby},
                {logic, turn_on_auto, logic},
                {logic, target_detected, logic},
                {logic, target_disappear, logic},
                {logic, being_hit, logic},
                {logic, ammunition_capacity_reached_limit, logic},
                {logic, HP_low, logic},
                {logic, logic_operate, logic},
                {logic, HP_regeneration, logic},
                {logic, outpost_HP_low, logic},
                {logic, revive, logic},
                {logic, outpost_destroyed, logic}},
};

/**
 * 联盟赛状态转移表格
 */
state_transform RMUL_state_table[STATE_NUM][EVENT_NUM]={
        /*******************              standby            *****************/
        {{standby, none, standby},
                {standby, match_begin, logic},
                {standby, turn_off_auto, standby},
                {standby, turn_on_auto, standby},
                {standby, target_detected, standby},
                {standby, target_disappear, standby},
                {standby, being_hit, standby},
                {standby, ammunition_capacity_reached_limit, standby},
                {standby, HP_low, standby},
                {standby, logic_operate, standby},
                {standby, HP_regeneration, standby}},


        /*******************              attack            *****************/
        {{attack, none, attack},
                {attack, match_begin, attack},
                {attack, turn_off_auto, standby},
                {attack, turn_on_auto, error},
                {attack, target_detected, attack},
                {attack, target_disappear, patrol},   //这里后续经过测试后才改成低级寻路
                {attack, being_hit, attack},
                {attack, ammunition_capacity_reached_limit, logic},
                {attack, HP_low, logic},
                {attack, logic_operate, logic},
                {attack, HP_regeneration, logic}},

        /*******************              high_priority_pathfinding            *****************/
        {{high_priority_pathfinding, none, high_priority_pathfinding},
                {high_priority_pathfinding, match_begin, error},
                {high_priority_pathfinding, turn_off_auto, standby},
                {high_priority_pathfinding, turn_on_auto, error},
                {high_priority_pathfinding, target_detected, high_priority_pathfinding},
                {high_priority_pathfinding, target_disappear, high_priority_pathfinding},
                {high_priority_pathfinding, being_hit, high_priority_pathfinding},
                {high_priority_pathfinding, ammunition_capacity_reached_limit, high_priority_pathfinding},
                {high_priority_pathfinding, HP_low, high_priority_pathfinding},
                {high_priority_pathfinding, logic_operate, high_priority_pathfinding},
                {high_priority_pathfinding, HP_regeneration, patrol}},

        /*******************              mid_priority_pathfinding            *****************/
        {{mid_priority_pathfinding, none, mid_priority_pathfinding},
                {mid_priority_pathfinding, match_begin, error},
                {mid_priority_pathfinding, turn_off_auto, standby},
                {mid_priority_pathfinding, turn_on_auto, error},
                {mid_priority_pathfinding, target_detected, mid_priority_pathfinding},
                {mid_priority_pathfinding, target_disappear, mid_priority_pathfinding},
                {mid_priority_pathfinding, being_hit, mid_priority_pathfinding},
                {mid_priority_pathfinding, ammunition_capacity_reached_limit, logic},
                {mid_priority_pathfinding, HP_low, logic},
                {mid_priority_pathfinding, logic_operate, mid_priority_pathfinding},
                {mid_priority_pathfinding, HP_regeneration, logic}},

        /*******************              low_priority_pathfinding            *****************/
        {{low_priority_pathfinding, none, low_priority_pathfinding},
                {low_priority_pathfinding, match_begin, error},
                {low_priority_pathfinding, turn_off_auto, standby},
                {low_priority_pathfinding, turn_on_auto, error},
                {low_priority_pathfinding, target_detected, attack},
                {low_priority_pathfinding, target_disappear, error},
                {low_priority_pathfinding, being_hit, low_priority_pathfinding},
                {low_priority_pathfinding, ammunition_capacity_reached_limit, logic},
                {low_priority_pathfinding, HP_low, logic},
                {low_priority_pathfinding, logic_operate, logic},
                {low_priority_pathfinding, HP_regeneration, low_priority_pathfinding}},

        /*******************              patrol            *****************/
        {{patrol, none, patrol},
                {patrol, match_begin, error},
                {patrol, turn_off_auto, standby},
                {patrol, turn_on_auto, error},
                {patrol, target_detected, attack},
                {patrol, target_disappear, patrol},
                {patrol, being_hit, patrol},
                {patrol, ammunition_capacity_reached_limit, logic},
                {patrol, HP_low, logic},
                {patrol, logic_operate, logic},
                {patrol, HP_regeneration, logic}},

        /*******************              stationary_defense            *****************/
        {{stationary_defense, none, stationary_defense},
                {stationary_defense, match_begin, error},
                {stationary_defense, turn_off_auto, standby},
                {stationary_defense, turn_on_auto, error},
                {stationary_defense, target_detected, stationary_defense},
                {stationary_defense, target_disappear, stationary_defense},
                {stationary_defense, being_hit, stationary_defense},  ///这里先测试，后面改为short_range_mobile_defense
                {stationary_defense, ammunition_capacity_reached_limit, constrained_defense},
                {stationary_defense, HP_low, constrained_defense},
                {stationary_defense, logic_operate, constrained_defense},
                {stationary_defense, HP_regeneration, logic}},


        /*******************              short_range_mobile_defense            *****************/
        {{constrained_defense, none, constrained_defense},
                {constrained_defense, match_begin, error},
                {constrained_defense, turn_off_auto, standby},
                {constrained_defense, turn_on_auto, error},
                {constrained_defense, target_detected, attack},
                {constrained_defense, target_disappear, patrol},
                {constrained_defense, being_hit, patrol},
                {constrained_defense, ammunition_capacity_reached_limit, constrained_defense},
                {constrained_defense, HP_low, constrained_defense},
                {constrained_defense, logic_operate, constrained_defense},
                {constrained_defense, HP_regeneration, logic}},


        /*******************              error            *****************/
        {{error, none, error},
                {error, match_begin, error},
                {error, turn_off_auto, standby},
                {error, turn_on_auto, error},
                {error, target_detected, error},
                {error, target_disappear, error},
                {error, being_hit, error},
                {error, ammunition_capacity_reached_limit, error},
                {error, HP_low, error},
                {error, logic_operate, error},
                {error, HP_regeneration, error}},


        /*******************              logic            *****************/
        {{logic, none, logic},
                {logic, match_begin, logic},
                {logic, turn_off_auto, standby},
                {logic, turn_on_auto, logic},
                {logic, target_detected, logic},
                {logic, target_disappear, logic},
                {logic, being_hit, logic},
                {logic, ammunition_capacity_reached_limit, logic},
                {logic, HP_low, logic},
                {logic, logic_operate, logic},
                {logic, HP_regeneration, logic}},

        /*******************              pursuit            *****************/
        {{pursuit, none, pursuit},
                {pursuit, match_begin, error},
                {pursuit, turn_off_auto, standby},
                {pursuit, turn_on_auto, error},
                {pursuit, target_detected, attack},
                {pursuit, target_disappear, error},
                {pursuit, being_hit, pursuit},
                {pursuit, ammunition_capacity_reached_limit, logic},
                {pursuit, HP_low, supply},
                {pursuit, logic_operate, error},
                {pursuit, HP_regeneration, pursuit},
                {pursuit, outpost_HP_low, supply},
                {pursuit, revive, logic},
                {pursuit, outpost_destroyed, constrained_defense}},


        /*******************              free_defense            *****************/
        {{free_defense, none, free_defense},
                {free_defense, match_begin, error},
                {free_defense, turn_off_auto, standby},
                {free_defense, turn_on_auto, error},
                {free_defense, target_detected, attack},
                {free_defense, target_disappear, error},
                {free_defense, being_hit, pursuit},
                {free_defense, ammunition_capacity_reached_limit, logic},
                {free_defense, HP_low, supply},
                {free_defense, logic_operate, error},
                {free_defense, HP_regeneration, free_defense},
                {free_defense, outpost_HP_low, error},
                {free_defense, revive, logic},
                {free_defense, outpost_destroyed, error}},

        /*******************              supply            *****************/
        {{supply, none, supply},
                {supply, match_begin, error},
                {supply, turn_off_auto, standby},
                {supply, turn_on_auto, error},
                {supply, target_detected, supply},
                {supply, target_disappear, supply},
                {supply, being_hit, supply},
                {supply, ammunition_capacity_reached_limit, supply},
                {supply, HP_low, supply},
                {supply, logic_operate, supply},
                {supply, HP_regeneration, supply},
                {supply, outpost_HP_low, supply},
                {supply, revive, logic},
                {supply, outpost_destroyed, supply}},

        /*******************              go_attack_outpost            *****************/
        {{go_attack_outpost, none, go_attack_outpost},
                {go_attack_outpost, match_begin, error},
                {go_attack_outpost, turn_off_auto, standby},
                {go_attack_outpost, turn_on_auto, error},
                {go_attack_outpost, target_detected, go_attack_outpost},
                {go_attack_outpost, target_disappear, go_attack_outpost},
                {go_attack_outpost, being_hit, go_attack_outpost},
                {go_attack_outpost, ammunition_capacity_reached_limit, logic},
                {go_attack_outpost, HP_low, error},
                {go_attack_outpost, logic_operate, go_attack_outpost},
                {go_attack_outpost, HP_regeneration, go_attack_outpost},
                {go_attack_outpost, outpost_HP_low, supply},
                {go_attack_outpost, revive, error},
                {go_attack_outpost, outpost_destroyed, supply}},
};


/**
 * 分区赛赛状态转移表格
 */
state_transform RMUC_state_table[STATE_NUM][EVENT_NUM]={
        /*******************              standby            *****************/
        {{standby, none, standby},

#if MATCH_MODE
                {standby, match_begin, patrol},
#elif CONSTRAINED_DEFENCE_DEBUG
                {standby, match_begin, constrained_defense},
#elif SUPPLY_DEFENCE_DEBUG
                {standby, match_begin, supply},
#elif FREE_DEFENCE_DEBUG
                {standby, match_begin, free_defence},
#else
                {standby, match_begin, patrol},
#endif

                {standby, turn_off_auto, standby},

#if MATCH_MODE
                {standby, turn_on_auto, standby},
#elif RADAR_DEBUG
                {standby, turn_on_auto, mid_priority_pathfinding},
#elif PATROL_DEBUG
                {standby, turn_on_auto, patrol},
#elif GO_ATTACK_OUTPOST_DEBUG
                {standby, turn_on_auto, go_attack_outpost},
#else
                {standby, turn_on_auto, standby},
#endif


                {standby, target_detected, standby},
                {standby, target_disappear, standby},
                {standby, being_hit, standby},
                {standby, ammunition_capacity_reached_limit, standby},
                {standby, HP_low, standby},
                {standby, logic_operate, standby},
                {standby, HP_regeneration, standby},
                {standby, outpost_HP_low, standby},
                {standby, revive, standby},
                {standby, outpost_destroyed, standby},
                {standby, radar_lock_target, standby},
                {standby, operator_intervene, standby}},


        /*******************              attack            *****************/
        {{attack, none, attack},
                {attack, match_begin, patrol},
                {attack, turn_off_auto, standby},
                {attack, turn_on_auto, patrol},
                {attack, target_detected, attack},
                {attack, target_disappear, pursuit},
                {attack, being_hit, attack},
                {attack, ammunition_capacity_reached_limit, supply},
                {attack, HP_low, supply},
                {attack, logic_operate, error},
                {attack, HP_regeneration, attack},
                {attack, outpost_HP_low, attack},
                {attack, revive, logic},
                {attack, outpost_destroyed, attack},
                {attack, radar_lock_target, attack},
                {attack, operator_intervene, logic}},

        /*******************              high_priority_pathfinding            *****************/
        {{high_priority_pathfinding, none, high_priority_pathfinding},
                {high_priority_pathfinding, match_begin, patrol},
                {high_priority_pathfinding, turn_off_auto, standby},
                {high_priority_pathfinding, turn_on_auto, patrol},
                {high_priority_pathfinding, target_detected, high_priority_pathfinding},
                {high_priority_pathfinding, target_disappear, high_priority_pathfinding},
                {high_priority_pathfinding, being_hit, high_priority_pathfinding},
                {high_priority_pathfinding, ammunition_capacity_reached_limit, high_priority_pathfinding},
                {high_priority_pathfinding, HP_low, high_priority_pathfinding},
                {high_priority_pathfinding, logic_operate, error},
                {high_priority_pathfinding, HP_regeneration, high_priority_pathfinding},
                {high_priority_pathfinding, outpost_HP_low, high_priority_pathfinding},
                {high_priority_pathfinding, revive, logic},
                {high_priority_pathfinding, outpost_destroyed, high_priority_pathfinding},
                {high_priority_pathfinding, radar_lock_target, high_priority_pathfinding},
                {high_priority_pathfinding, operator_intervene, logic}},

        /*******************              mid_priority_pathfinding            *****************/
        {{mid_priority_pathfinding, none, mid_priority_pathfinding},
                {mid_priority_pathfinding, match_begin, patrol},
                {mid_priority_pathfinding, turn_off_auto, standby},
                {mid_priority_pathfinding, turn_on_auto, patrol},
                {mid_priority_pathfinding, target_detected, mid_priority_pathfinding},
                {mid_priority_pathfinding, target_disappear, mid_priority_pathfinding},
                {mid_priority_pathfinding, being_hit, mid_priority_pathfinding},
                {mid_priority_pathfinding, ammunition_capacity_reached_limit, supply},
                {mid_priority_pathfinding, HP_low, supply},
                {mid_priority_pathfinding, logic_operate, error},
                {mid_priority_pathfinding, HP_regeneration, mid_priority_pathfinding},
                {mid_priority_pathfinding, outpost_HP_low, mid_priority_pathfinding},
                {mid_priority_pathfinding, revive, logic},
                {mid_priority_pathfinding, outpost_destroyed, mid_priority_pathfinding},
                {mid_priority_pathfinding, radar_lock_target, mid_priority_pathfinding},
                {mid_priority_pathfinding, operator_intervene, logic}},

        /*******************              low_priority_pathfinding            *****************/
        {{low_priority_pathfinding, none, low_priority_pathfinding},
                {low_priority_pathfinding, match_begin, patrol},
                {low_priority_pathfinding, turn_off_auto, standby},
                {low_priority_pathfinding, turn_on_auto, patrol},
                {low_priority_pathfinding, target_detected, attack},
                {low_priority_pathfinding, target_disappear, low_priority_pathfinding},        //这里error不具备鲁棒性，如果需要使用该状态需要更改
                {low_priority_pathfinding, being_hit, low_priority_pathfinding},
                {low_priority_pathfinding, ammunition_capacity_reached_limit, supply},
                {low_priority_pathfinding, HP_low, supply},
                {low_priority_pathfinding, logic_operate, error},
                {low_priority_pathfinding, HP_regeneration, low_priority_pathfinding},
                {low_priority_pathfinding, outpost_HP_low, low_priority_pathfinding},
                {low_priority_pathfinding, revive, logic},
                {low_priority_pathfinding, outpost_destroyed, low_priority_pathfinding},
                {low_priority_pathfinding, radar_lock_target, low_priority_pathfinding},
                {low_priority_pathfinding, operator_intervene, logic}},

        /*******************              patrol            *****************/
        {{patrol, none, patrol},
                {patrol, match_begin, patrol},
                {patrol, turn_off_auto, standby},
                {patrol, turn_on_auto, patrol},
                {patrol, target_detected, attack},
                {patrol, target_disappear, patrol},
                {patrol, being_hit, patrol},
                {patrol, ammunition_capacity_reached_limit, supply},
                {patrol, HP_low, supply},
                {patrol, logic_operate, error},
                {patrol, HP_regeneration, patrol},
                {patrol, outpost_HP_low, patrol},
                {patrol, revive, logic},
                {patrol, outpost_destroyed, patrol},
                {patrol, radar_lock_target, logic},
                {patrol, operator_intervene, logic}},

        /*******************              stationary_defense            *****************/
        {{stationary_defense, none, stationary_defense},
                {stationary_defense, match_begin, patrol},
                {stationary_defense, turn_off_auto, standby},
                {stationary_defense, turn_on_auto, patrol},
                {stationary_defense, target_detected, stationary_defense},
                {stationary_defense, target_disappear, stationary_defense},
                {stationary_defense, being_hit, stationary_defense},
                {stationary_defense, ammunition_capacity_reached_limit, supply},
                {stationary_defense, HP_low, supply},
                {stationary_defense, logic_operate, error},
                {stationary_defense, HP_regeneration, stationary_defense},
                {stationary_defense, outpost_HP_low, supply},
                {stationary_defense, revive, logic},
                {stationary_defense, outpost_destroyed, stationary_defense},
                {stationary_defense, radar_lock_target, stationary_defense},
                {stationary_defense, operator_intervene, logic}},


        /*******************              constrained_defense            *****************/
        {{constrained_defense, none, constrained_defense},
                {constrained_defense, match_begin, patrol},
                {constrained_defense, turn_off_auto, standby},
                {constrained_defense, turn_on_auto, patrol},
                {constrained_defense, target_detected, constrained_defense},
                {constrained_defense, target_disappear, constrained_defense},
                {constrained_defense, being_hit, constrained_defense},
                {constrained_defense, ammunition_capacity_reached_limit, constrained_defense},
                {constrained_defense, HP_low, constrained_defense},
                {constrained_defense, logic_operate, constrained_defense},
                {constrained_defense, HP_regeneration, constrained_defense},
                {constrained_defense, outpost_HP_low, constrained_defense},
                {constrained_defense, revive, logic},
                {constrained_defense, outpost_destroyed, constrained_defense},
                {constrained_defense, radar_lock_target, constrained_defense},
                {constrained_defense, operator_intervene, logic}},


        /*******************              error            *****************/
        {{error, none, error},
                {error, match_begin, patrol},
                {error, turn_off_auto, standby},
                {error, turn_on_auto, patrol},
                {error, target_detected, error},
                {error, target_disappear, error},
                {error, being_hit, error},
                {error, ammunition_capacity_reached_limit, error},
                {error, HP_low, error},
                {error, logic_operate, error},
                {error, HP_regeneration, error},
                {error, outpost_HP_low, error},
                {error, revive, error},
                {error, outpost_destroyed, error},
                {error, radar_lock_target, error},
                {error, operator_intervene, error}},


        /*******************              logic            *****************/
        {{logic, none, logic},
                {logic, match_begin, patrol},
                {logic, turn_off_auto, standby},
                {logic, turn_on_auto, logic},
                {logic, target_detected, logic},
                {logic, target_disappear, logic},
                {logic, being_hit, logic},
                {logic, ammunition_capacity_reached_limit, logic},
                {logic, HP_low, logic},
                {logic, logic_operate, logic},
                {logic, HP_regeneration, logic},
                {logic, outpost_HP_low, supply},
                {logic, revive, logic},
                {logic, outpost_destroyed, logic},
                {logic, radar_lock_target, logic},
                {logic, operator_intervene, logic}},


        /*******************              pursuit            *****************/
        {{pursuit, none, pursuit},
                {pursuit, match_begin, patrol},
                {pursuit, turn_off_auto, standby},
                {pursuit, turn_on_auto, patrol},
                {pursuit, target_detected, attack},
                {pursuit, target_disappear, pursuit},
                {pursuit, being_hit, pursuit},
                {pursuit, ammunition_capacity_reached_limit, supply},
                {pursuit, HP_low, supply},
                {pursuit, logic_operate, error},
                {pursuit, HP_regeneration, pursuit},
                {pursuit, outpost_HP_low, pursuit},
                {pursuit, revive, logic},
                {pursuit, outpost_destroyed, pursuit},
                {pursuit, radar_lock_target, logic},
                {pursuit, operator_intervene, logic}},


        /*******************              free_defense            *****************/
        {{free_defense, none, free_defense},
                {free_defense, match_begin, patrol},
                {free_defense, turn_off_auto, standby},
                {free_defense, turn_on_auto, patrol},
                {free_defense, target_detected, attack},
                {free_defense, target_disappear, free_defense},
                {free_defense, being_hit, pursuit},
                {free_defense, ammunition_capacity_reached_limit, supply},
                {free_defense, HP_low, supply},
                {free_defense, logic_operate, error},
                {free_defense, HP_regeneration, free_defense},
                {free_defense, outpost_HP_low, free_defense},
                {free_defense, revive, logic},
                {free_defense, outpost_destroyed, free_defense},
                {free_defense, radar_lock_target, logic},
                {free_defense, operator_intervene, logic}},

        /*******************              supply            *****************/
        {{supply, none, supply},
                {supply, match_begin, patrol},
                {supply, turn_off_auto, standby},
                {supply, turn_on_auto, patrol},
                {supply, target_detected, supply},
                {supply, target_disappear, supply},
                {supply, being_hit, supply},
                {supply, ammunition_capacity_reached_limit, supply},
                {supply, HP_low, supply},
                {supply, logic_operate, supply},
                {supply, HP_regeneration, supply},
                {supply, outpost_HP_low, supply},
                {supply, revive, logic},
                {supply, outpost_destroyed, constrained_defense},
                {supply, radar_lock_target, supply},
                {supply, operator_intervene, logic}},

        /*******************              go_attack_outpost            *****************/
        {{go_attack_outpost, none, go_attack_outpost},
                {go_attack_outpost, match_begin, patrol},
                {go_attack_outpost, turn_off_auto, standby},
                {go_attack_outpost, turn_on_auto, patrol},
                {go_attack_outpost, target_detected, go_attack_outpost},
                {go_attack_outpost, target_disappear, go_attack_outpost},
                {go_attack_outpost, being_hit, go_attack_outpost},
                {go_attack_outpost, ammunition_capacity_reached_limit, supply},
                {go_attack_outpost, HP_low, supply},
                {go_attack_outpost, logic_operate, go_attack_outpost},
                {go_attack_outpost, HP_regeneration, go_attack_outpost},
                {go_attack_outpost, outpost_HP_low, go_attack_outpost},
                {go_attack_outpost, revive, logic},
                {go_attack_outpost, outpost_destroyed, go_attack_outpost},
                {go_attack_outpost, radar_lock_target, go_attack_outpost},
                {go_attack_outpost, operator_intervene, logic}},


};


